{
  "properties" : { },
  "id" : "0de72c688cf146c9bd667417ad585dba",
  "script" : null,
  "groupId" : "e6cd7933a0e746b8b4af97af80c9c45c",
  "name" : "erupt",
  "createTime" : 1728702394481,
  "updateTime" : 1728441978025,
  "lock" : null,
  "createBy" : null,
  "updateBy" : null,
  "path" : "/erupt",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"tn\":\"tb_res_staff\"\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"msg\": \"success\",\n    \"data\": {\n        \"id\": 12,\n        \"createBy\": null,\n        \"createTime\": null,\n        \"updateBy\": null,\n        \"updateTime\": null,\n        \"className\": \"Staff\",\n        \"name\": \"员工信息\",\n        \"remark\": null,\n        \"tableName\": \"tb_res_staff\"\n    },\n    \"status\": 0\n}",
  "description" : null,
  "requestBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "tn",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "msg",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "aaa_bb",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "status",
      "value" : "0",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import cn.hutool.core.util.StrUtil
import xyz.erupt.generator.model.GeneratorField
import xyz.erupt.jpa.dao.EruptDao
import xyz.erupt.generator.model.GeneratorClass
import log

var tn = body.tn

var tb = db.selectOne("""
    select * from e_generator_class where table_name=#{tn}
""")

if (!tb){
    GeneratorClass gc = new GeneratorClass()
    gc.setTableName(tn)
    gc.setClassName("Staff")
    gc.setName("员工信息")
    EruptDao.persistAndFlush(gc)
    tb = db.selectOne("""
        select * from e_generator_class where table_name=#{tn}
    """)
}
var cl = db.select("""
    select * from e_generator_field where class_id=#{tb.id}
""")
var cns = ['id','create_by','create_time','update_by','update_time']
for (c in cl) {
    cns.push(c.fieldName)
}
var cinfo = db.select("""
    SELECT DATA_TYPE dtype,CHARACTER_MAXIMUM_LENGTH mlength,COLUMN_NAME cname,
        COLUMN_COMMENT ccomment,IS_NULLABLE isnull
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = 'magic' AND TABLE_NAME = #{tn} 
    and COLUMN_NAME not in (#{cns})  order by ORDINAL_POSITION;
""")
var sort = cl.size()+1
for (item in cinfo) {
    var gf = {
		"field_name" : StrUtil.toCamelCase(item.cname),
		"is_show" : 1,
		"not_null" : 0,
		"query" : 0,
		"show_name" : item.ccomment,
		"sort" : sort,
		"sortable" : 0,
		"type" : "INPUT",
		"class_id" : tb.id
	}
    if (item.dtype.equals("date")){
        gf.type = "DATE"
    }
    if (item.dtype.equals("datetime")){
        gf.type = "DATETIME"
    }
    if (item.dtype.equals("int")){
        gf.type = "NUMBER"
    }
    db.table("e_generator_field").primary("id").save(gf)
    sort++
}
return tb
